var t = getApp(), a = !1;

Page({
    data: {
        show: !1,
        show1: !1,
        receive_logs_lastPage: 1,
        receive_logs_Page: 1,
        goods_list_lastPage: 1,
        goods_list_page: 1,
        info: [],
        color: []
    },
    onLoad: function(a) {
        this.getData(), this.share();
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        }), a.mid && t._setMid(a.mid);
    },
    swipeToTop: function(t) {
        var a = t.detail.current;
        this.data.receive_logs_Page < this.data.receive_logs_lastPage && this.data.info.receive_logs.data.length - 14 == a && this.getMore("log", this.data.receive_logs_Page + 1);
    },
    tapGo: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    closeBtn: function() {
        this.setData({
            show1: !1
        });
    },
    init: function() {},
    closeShow: function() {
        this.setData({
            show: !1
        }), this.init(), this.getData();
    },
    toPage: function(t) {
        var a, e = t.currentTarget.dataset.tag;
        "record" == e ? a = "/packageC/redPacket/get_red_record/get_red_record?tag=new" : "amount" == e ? a = "/packageC/redPacket/red_amount/red_amount?tag=new" : "rank" == e && (a = "/packageC/redPacket/redRank/redRank"), 
        wx.navigateTo({
            url: a
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.shareinfo.share_title,
            path: "/packageC/redPacket/daily_red_home/daily_red_home?mid=" + a,
            imageUrl: this.data.shareinfo.share_pictures
        };
    },
    sureGet: function(e) {
        var o = e.currentTarget.dataset.value;
        if (1 == o) {
            if (a) return void console.log("等请求完才能重新点击");
            a = !0;
            var s = this, i = t.getNetAddresss("plugin.redpack-tool.frontend.redpack.index");
            t._postNetWork({
                url: i,
                success: function(t) {
                    var e = t.data;
                    console.log(e), 1 == e.result ? s.setData({
                        show: !0,
                        amount: e.data.amount
                    }) : e.data.alert ? s.setData({
                        show1: !0
                    }) : wx.showToast({
                        title: e.msg
                    }), a = !1;
                },
                fail: function(t) {
                    console.log(t), a = !1;
                }
            });
        } else 0 == o ? console.log("不可领取状态") : -2 == o ? wx.showToast({
            title: "当前红包已领完"
        }) : -1 == o && wx.showToast({
            title: "额度不足"
        });
    },
    getData: function() {
        wx.showLoading({
            title: "加载中"
        });
        var a = this, e = t.getNetAddresss("plugin.redpack-tool.frontend.homePage.index");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                console.log(e), 1 == e.result ? (e.data.quota_info.quota_total = Number(e.data.quota_info.quota_total), 
                e.data.quota_info.use_total = Number(e.data.quota_info.use_total), a.setData({
                    info: e.data,
                    goods_list_lastPage: e.data.goods_list.last_page,
                    receive_logs_lastPage: e.data.receive_logs.last_page,
                    bfbMum: 100 * (Number(e.data.quota_info.use_total) / Number(e.data.quota_info.quota_total)).toFixed(2) >= 100 ? "100%" : 100 * (Number(e.data.quota_info.use_total) / Number(e.data.quota_info.quota_total)).toFixed(2) + "%"
                }), wx.setNavigationBarTitle({
                    title: e.data.plugin_name
                })) : wx.showToast({
                    title: e.msg
                }), wx.hideLoading({
                    success: function(t) {}
                });
            },
            fail: function(t) {
                console.log(t), wx.hideLoading({
                    success: function(t) {}
                });
            }
        });
    },
    tapMore: function() {
        this.getMore("goods", this.data.goods_list_lastPage);
    },
    getMore: function(a, e) {
        var o = this, s = {};
        if ("log" == a) s.log_page = e; else {
            if (e >= this.goods_list_lastPage) return;
            this.setData({
                goods_list_page: e + 1
            }), s.goods_page = this.data.goods_list_page;
        }
        var i = t.getNetAddresss("plugin.redpack-tool.frontend.homePage.index");
        t._postNetWork({
            url: i,
            data: JSON,
            success: function(t) {
                var e, s, i = t.data;
                1 == i.result ? (console.log(i), "log" == a ? (e = i.data.receive_logs.data, s = o.data.info.receive_logs.data.concat(e), 
                o.data.info.receive_logs.data = s, o.setData({
                    info: o.data.info,
                    receive_logs_lastPage: i.data.receive_logs.last_page
                })) : (e = i.data.goods_list.data, s = o.data.info.goods_list.data.concat(e), o.data.info.goods_list.data = s, 
                o.setData({
                    info: o.data.info,
                    goods_list_lastPage: i.data.goods_list.last_page
                }))) : wx.showToast({
                    title: i.msg
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    share: function() {
        var a = this, e = t.getNetAddresss("plugin.redpack-tool.frontend.share.index");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                console.log(e), 1 == e.result ? a.setData({
                    shareinfo: e.data
                }) : wx.showToast({
                    title: e.msg
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    goPersonred: function() {
        wx.navigateTo({
            url: "/packageI/personRed/personRed/personRed"
        });
    }
});